package com.taskinception;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.taskinception.connectivity.DatabaseAdapter;
import com.taskinception.model.Task;
import com.taskinception.utils.Alert;

public class TaskDetailsActivity extends Activity {

    private DatabaseAdapter mDbAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	Bundle extras = getIntent().getExtras();
	if (extras == null
		|| !extras.containsKey(TaskActivity.TAG_CURRENT_TASK)) {
	    Alert.message(TaskDetailsActivity.this,
		    android.R.string.dialog_alert_title,
		    R.string.unintended_activity_entrance,
		    new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
			    finish();
			}
		    });
	    return;
	}

	setContentView(R.layout.task_details);

	mDbAdapter = new DatabaseAdapter(this).open();

	long currentTaskId = extras.getLong(TaskActivity.TAG_CURRENT_TASK);
	Task task = mDbAdapter.fetchTask(currentTaskId);

	TextView body = (TextView) findViewById(R.id.task_body);
	if (task.getBody().isEmpty()) {
	    body.setVisibility(View.GONE);
	} else {
	    body.setText(task.getBody());
	}
    };

}
